package servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.Servicet;

@WebServlet("/Borrow")
public class BorrowServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Servicet s = new Servicet();
     
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		SimpleDateFormat gs = new SimpleDateFormat("yyyy-MM-dd");
		String date = gs.format(new Date());
		String name = request.getParameter("name");
		String sm = request.getParameter("text");
		if("".equals(name) || "".equals(sm)) {
			request.getRequestDispatcher("aaa/noSucceed.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("aaa/succeed.jsp").forward(request, response);
			s.add(date, name, sm);			
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
